<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>水平居中</title>
  <style>
    .item {
      background-color: orange;
    }
    .box {
      width: 100%;
      height: 200px;
      border: 1px solid black;
      margin-top: 50px;
    }

    /* 行内元素 */
    .box-1 {
      text-align: center;
    }

    /* 块级元素 */
    .box-2 .item {
      width: 100px;
      margin: 0 auto;
    }

    /* absolute */
    .box-3 {
      position: relative;
    }
    .box-3 .item {
      position: absolute;
      width: 150px;
      height: 100px;
      left: 50%;
      margin-left: -75px;
    }
  </style>
</head>
<body>
  <!-- 行内inline元素 -->
  <div class="box box-1">
    <span>Content</span>
  </div>

  <!-- 块级block元素 -->
  <div class="box box-2" >
    <div class="item">Item</div>
  </div>

  <!-- absolute -->
  <div class="box box-3">
    <div class="item">Item</div>
  </div>
</body>
</html>